package com.project.module.zlXiang.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.framework.aspectj.lang.annotation.Log;
import com.framework.aspectj.lang.enums.BusinessType;
import com.framework.web.controller.BaseController;
import com.framework.web.page.TableDataInfo;
import com.framework.web.domain.AjaxResult;
import com.common.utils.poi.ExcelUtil;

import com.project.module.zlXiang.domain.ZlXiang;
import com.project.module.zlXiang.service.IZlXiangService;

/**
 * 乡镇基本 控制层和页面
 * 
 * @author ruoyi
 * @date 2018-09-14
 */
@Controller
@RequestMapping("/module/zlXiang")
public class ZlXiangController extends BaseController
{
    private String prefix = "module/zlXiang";
	
	@Autowired
	private IZlXiangService zlXiangService;
	
	@RequiresPermissions("module:zlXiang:view")
	@GetMapping()
	public String zlXiang()
	{
	    return prefix + "/zlXiang";
	}
	
	/**
	 * 查询乡镇基本列表
	 */
	@RequiresPermissions("module:zlXiang:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZlXiang zlXiang)
	{
		startPage();
        List<ZlXiang> list = zlXiangService.selectZlXiangList(zlXiang);
		return getDataTable(list);
	}


    @Log(title = "乡镇基本", businessType = BusinessType.EXPORT)
    @RequiresPermissions("module:zlXiang:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZlXiang zlXiang) throws Exception
    {
        try
        {
            List<ZlXiang> list = zlXiangService.selectZlXiangList(zlXiang);
            ExcelUtil<ZlXiang> util = new ExcelUtil<ZlXiang>(ZlXiang.class);
            return util.exportExcel(list, "ZlXiang");
        }
        catch (Exception e)
        {
            return error("导出Excel失败，请联系系统管理员！");
        }
    }


    /**
	 * 新增乡镇基本
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存乡镇基本
	 */
	@RequiresPermissions("module:zlXiang:add")
	@Log(title = "乡镇基本", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZlXiang zlXiang)
	{		
		return toAjax(zlXiangService.insertZlXiang(zlXiang));
	}

	/**
	 * 修改乡镇基本
	 */
	@GetMapping("/edit/{qybm}")
	public String edit(@PathVariable("qybm") String qybm, ModelMap mmap)
	{
		ZlXiang zlXiang = zlXiangService.selectZlXiangById(qybm);
		mmap.put("zlXiang", zlXiang);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存乡镇基本
	 */
	@RequiresPermissions("module:zlXiang:edit")
	@Log(title = "乡镇基本", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZlXiang zlXiang)
	{		
		return toAjax(zlXiangService.updateZlXiang(zlXiang));
	}
	
	/**
	 * 删除乡镇基本
	 */
	@RequiresPermissions("module:zlXiang:remove")
	@Log(title = "乡镇基本", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(zlXiangService.deleteZlXiangByIds(ids));
	}
	
}
